# 将商品所有表进行合并

from goods.models import *


def get_goods(goods_list):
    # 遍历商品
    for i in goods_list:
        # 获取指定id详情图
        goodsImg = GoodsImg.objects.filter(goods_id=i['goods_id']).values()
        for img in goodsImg:
            i['goods_images'] = [value for value in img.values()][2:]
        # 获取展示图
        goodsShow = GoodsShow.objects.filter(goods_id=i['goods_id']).values()
        for show in goodsShow:
            i['goods_shows'] = [value for value in show.values()][2:]
        # 获取商品款式
        goodsStyle = GoodsStyle.objects.filter(goods_id=i['goods_id']).values()
        for style in goodsStyle:
            i['goods_styles'] = [value for value in style.values()][2:]
    # 返回商品数据
    return goods_list


def goods_item(mode_to):
    # 获取指定id详情图
    goodsImg = GoodsImg.objects.filter(goods_id=mode_to['goods_id']).values()
    for img in goodsImg:
        mode_to['goods_images'] = [value for value in img.values()][2:]
    # 获取展示图
    goodsShow = GoodsShow.objects.filter(goods_id=mode_to['goods_id']).values()
    for show in goodsShow:
        mode_to['goods_shows'] = [value for value in show.values()][2:]
    # 获取商品款式
    goodsStyle = GoodsStyle.objects.filter(goods_id=mode_to['goods_id']).values()
    for style in goodsStyle:
        mode_to['goods_styles'] = [value for value in style.values()][2:]

    return mode_to
